Operators in ST

Operators execute operations and provide functionality, such as addition. The operators combine the operands to form expressions.

Possible operators

No.

Description of operation:

symbol

Examples

Precedence

Corresponding
standard block

1

parentheses:

(expression)

A + (B / C)

(A + B) / C

A / (B + C)

12 (highest)

 

2

call of function or call of a method, if there is a return value:

identifier (parameter list)

ABS(A)

ADD(X,Y)

11

 

3

dereference

^

Details: see under "Declaration of reference variables (incl. assignments to them)"

R^

10

 

4

negation:

–A

9

 

5

unary plus:

+

+B

9

 

6

complement:

NOT

NOT C

9

NOT block

7

exponentiation:

**

A ** B

B ** B

8

EXPT block

8

multiply:

*

A * B

7

MUL block

9

divide:

/

A / B

A / B / D

7

DIV block

10

modulo:

MOD

A MOD B

7

MOD block

11

add:

+

A + B

A + B + C

6

ADD block

12

subtract:

A – B

A – B – C

6

SUB block

13

comparison:

<, >, <=, >=

A < B

5

LT block,
GT block,
LE block,
GE block

14

equality:

=

A = B

A = B & B = C

4

EQ block

15

inequality:

<>

A <> B

4

NE block

16a

Boolean AND:

&

A & B

A & B & C

3

AND block

16b

Boolean AND:

AND

A AND B

3

AND block

17

Boolean exclusive OR:

XOR

A XOR B

2

XOR block

18

Boolean OR:

OR

A OR B

1 (lowest)

OR block

Notes:

  • Operators can be →overloaded.

  • Only the following operators can be applied to the datatypes STRING and CHAR=, <>, <, >, <=, >=

Deviation from IEC-standard

The operators for comparison <, >, <=, >= are evaluated with a higher precedence than the operator for equality = and the operators for inequality <>
This evaluation is a deviation from the →IEC-standard (edition 3.0) "Table 71 – Operators of the ST language". The table specifies that these operators are of the same precedence.
However, the evaluation of these operators in Neuron Power Engineer is done in accordance with the specifications of the IEC-standard (Edition 3.0) "Annex A Formal specification of the languages elements, Table 71 - 72 - Language Structured Text (ST)". These specifications are also in accordance with the preceding IEC-standard (2nd Edition) "Table 55 - Operators of the ST language".

  • Only the equality operator = and the inequality operator <> can be applied to declared variables based on an →interface and NULL.

Comparing variables based on an interface or of such a variable with NULL
interface_variable_1 = interface_variable_2
interface_variable_1 = NULL
NULL = interface_variable_2
  • The column "Corresponding standard block" informs which operator returns the same results as the corresponding standard block. The condition is that the operator works with the same data as the standard block. Example: Expression x+y for the addition has a behavior identical to this call of the ADD blockADD(x,y)Observe: If the block description contains the warnung "No check of invalid connections", this warnung also applies to the corresponding ST-operator. This warning looks like this (or it is simular to it):

No check of invalid connections

For some blocks, invalid connections are not checked by Neuron Power Engineer. Therefore, enter code in your application to detect invalid connections (e.g. IF-statements in the ST-code).

See "Standard blocks for the application" for information what the consequences of an invalid connection might be.

Deviation from IEC-standard

The "no check of invalid connections" is a deviation from the →IEC-standard that demands an error handling, if the result of the block exceeds the range of values for the output data type. This deviation also applies to the corresponding ST-operator.

  • On other errors (e.g. in case of a division by 0), the value 0 is returned but the output ENO of the embracing →POU is not set to value FALSE (or an equivalent).

  • Mind the correct combination of the →literals/→variables for multiplication, division, addition and subtraction, if the operation is done for literals/variables of data type TIME. Other combinations will be highlighted as faulty.

operation: symbol

data type for operand and result

example

behavior identical to this block

multiply: *

  • 1st operand: data type TIME

  • all following operands: data type belonging to →generic data type ANY_NUM

  • result: data type TIME

T#1m40s * 2 * 5

MUL_TIME block, with:
1st operand = IN1, all following operands are handled as IN2 is handled, result = return value

divide: /

  • 1st operand: data type TIME

  • 2nd operand: data type belonging to ANY_NUM

  • result: data type TIME

T#1m40s / 2

DIV_TIME block, with:
1st operand = IN1, 2nd operand = IN2, result = return value The operator / calculates using the accuracy as entered for the 2nd operand. That means: If the 2nd operand is a REAL value, Neuron Power Engineer is using a REAL value for the internal calculation. Compare: DIV_TIME is using LREAL for the internal calculation.

add: +

  • 1st operand: data type TIME

  • all following operands: data type TIME

  • result: data type TIME

T#3s + T#4s + T#1s

ADD_TIME block, with:
1st operand = IN1, all following operands are handled as IN2 is handled, result = return value

subtract: -

  • 1st operand: data type TIME
    2nd operand: data type TIME

  • result: data type TIME

T#4s - T#3s

SUB_TIME block, with:
1st operand = IN1, 2nd operand = IN2, result = return value